/*********************************************************************************/
/*                                                                               */
/*      SPI Driver                                                               */
/*                                                                               */
/*      Last updated by:   CBS                                                   */
/*      Last update date:  13/01/15                                              */
/*      Revision:          0                                                     */
/*      Copyright:         DENSO                                                 */
/*                                                                               */
/*********************************************************************************/
/*********************************************************************************/
/*  include files                                                                */
/*********************************************************************************/
#include "Spi.h"
#include <stdlib.h>

/*********************************************************************************/
/*  defines / data types / structs / unions / macros                             */
/*********************************************************************************/
/* SPI_A */
#define SPI_A_CS_E2     2
#define SPI_A_CS_FLASH  1

/* SPI_B */
#define SPI_B_CS_E2     0

const Spi_SequenceConfigType SpiSequenceConfigData[] =
{
    {
        SPI_SEQ_TEST,
        { SPI_JOB_TEST_0,SPI_JOB_TEST_1,SPI_JOB_TEST_2,SPI_JOB_TEST_3,(-1)}, 
    },
};


const Spi_JobConfigType SpiJobConfigData[] =
{
    {
        SPI_JOB_TEST_0,
        DSPI_CTRL_A,
        { SPI_CH_TEST_0,(-1)},
        SPI_EXT_DEVICE_A_E2,
    },
    {
        SPI_JOB_TEST_1,
        DSPI_CTRL_A,
        { SPI_CH_TEST_0,SPI_CH_TEST_1,(-1)},
        SPI_EXT_DEVICE_A_E2,
    },
    {
        SPI_JOB_TEST_2,
        DSPI_CTRL_A,
        { SPI_CH_TEST_0,SPI_CH_TEST_1 ,SPI_CH_TEST_2,(-1)},
        SPI_EXT_DEVICE_A_E2,
    },
    {
        SPI_JOB_TEST_3,
        DSPI_CTRL_A,
        { SPI_CH_TEST_0,SPI_CH_TEST_1,SPI_CH_TEST_2,SPI_CH_TEST_3,(-1)},
        SPI_EXT_DEVICE_A_E2,
    },
};

U4 Spi_GetJobCnt(void){
    return (sizeof(SpiJobConfigData)/sizeof(SpiJobConfigData[0]));
}

/* Channels */
const Spi_ChannelConfigType SpiChannelConfigData[] =
{
    {
        SPI_CH_TEST_0,
        SPI_IB,
        16,
        0x11,
        SPI_EB_MAX_LENGTH,
        0x04,
        FALSE
    },
    {
        SPI_CH_TEST_0,
        SPI_IB,
        16,
        0x22,
        SPI_EB_MAX_LENGTH,
        0x04,
        FALSE
    },
    {
        SPI_CH_TEST_0,
        SPI_IB,
        16,
        0x33,
        SPI_EB_MAX_LENGTH,
        0x04,
        FALSE
    },
    {
        SPI_CH_TEST_0,
        SPI_IB,
        16,
        0x44,
        SPI_EB_MAX_LENGTH,
        0x04,
        FALSE
    },
};

U4 Spi_GetChannelCnt(void )
{
    return sizeof(SpiChannelConfigData)/sizeof(SpiChannelConfigData[0]); 
}

const Spi_ExternalDeviceType SpiExternalConfigData[] =
{
    /* SPI_EXT_DEVOCE_A_E2 */
    {
        1000000UL,
        SPI_A_CS_E2,
        STD_LOW,
        SPI_EDGE_LEADING,
        1,
        STD_LOW,
        606,
        606,
    },
    {
        1000000UL,
        SPI_A_CS_FLASH,
        STD_LOW,
        SPI_EDGE_LEADING,
        1,
        STD_LOW,
        606,
        606,
    },
    
    {
        1000000UL,
        SPI_B_CS_E2,
        STD_LOW,
        SPI_EDGE_LEADING,
        1,
        STD_LOW,
        0,
        0,
    },
};

U4 Spi_GetExternalDeviceCnt(void )
{
    return sizeof(SpiExternalConfigData)/sizeof(SpiExternalConfigData[0]); 
}

const Spi_HwConfigType SpiHwConfig[] =
{
    {
        TRUE,
        DMA_SPI_A_RECEIVE_CHANNEL,
        DMA_SPI_A_TRANSMIT_CHANNEL,
    },
    {
        TRUE,
        DMA_SPI_B_RECEIVE_CHANNEL,
        DMA_SPI_B_TRANSMIT_CHANNEL,
    }
};

const Spi_DriverType SpiConfigData =
{
    SPI_MAX_CHANNEL,
    SPI_MAX_JOB,
    SPI_MAX_SEQUENCE,
    &SpiChannelConfigData[0],
    &SpiExternalConfigData[0],
    &SpiJobConfigData[0],
    &SpiSequenceConfigData[0],
    &SpiHwConfig[0],
};

static const Spi_ConfigType* ConfigPtr = & SpiConfigData; 

/*********************************************************************************/
/*  API Functions                                                                */
/*********************************************************************************/